package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.Dto.DishDto;
import com.itheima.reggie.Dto.SetmealDto;
import com.itheima.reggie.common.Result;
import com.itheima.reggie.entity.Dish;
import com.itheima.reggie.entity.Setmeal;
import com.itheima.reggie.entity.SetmealDish;
import com.itheima.reggie.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Yan
 * @date 2022/3/1
 */
@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    @PostMapping
    public Result<String> addSetmeal(@RequestBody SetmealDto setmealDto){
        return setmealService.addSetmeal(setmealDto);
    }

    @GetMapping("page")
    public Result<Page<SetmealDto>> findSetmealByPage(Long page, Long pageSize, String name){
        return setmealService.findSetmealByPage(page,pageSize,name);
    }


    @DeleteMapping
    public Result<String> deleteSetmeal(@RequestParam List<Long> ids){
        return setmealService.deleteSetmeal(ids);
    }


    @PostMapping("status/{status}")
    public Result<String> status(@PathVariable Integer status,@RequestParam List<Long> ids){
        return setmealService.status(status,ids);
    }

    @GetMapping("{id}")
    public Result<SetmealDto> findSetmealById(@PathVariable Long id){
        return setmealService.findSetmealById(id);
    }


    @PutMapping
    public Result<String> updateSetmeal(@RequestBody SetmealDto setmealDto){
        return setmealService.updateSetmeal(setmealDto);
    }

    /**
     * 查询套餐
     * @param categoryId
     * @param status
     * @return
     */
    @GetMapping("/list")
    public Result<List<Setmeal>> setmealList(Long categoryId,Integer status){
        return setmealService.setmealList(categoryId,status);
    }

    @GetMapping("/dish/{setmealId}")
    public Result<List<DishDto>>  getSetmealDishList(@PathVariable Long setmealId){
        return setmealService.getSetmealDishList(setmealId);
    }
}
